package roborally.util;

import java.util.Comparator;

import roborally.Pieces.Item;
/**
 * This is a class representing a Comparator used to sort CarriablePieces according to their weight.
 * 
 * @version 3.0
 * @author 	Bart Opsomer 2de Bachelor Ingenieurswetenschappen Electrotechniek-Computerwetenschappen 
 * 		   	Peter Opsomer 1ste Master Wiskundige IngenieursTechnieken
 */
public class WeightComparator implements Comparator<Item> {
	/**
	 * Compare two CarriablePieces. The method is used as a sorting criterion in Robot for CarriablePieces by descending weight.
	 * 
	 * @param battery1 the first CarriablePiece (which is always a Battery in version 2.0 of the project)
	 * @param battery2 the second CarriablePiece
	 * @return 	a positive number if battery1 has less weight than battery2, negative if lower and 0 if they have the same weight
	 * 			| Math.sign(battery2.getWeight() - battery1.getWeight())
	 */
	@Override
	public int compare(Item battery1, Item battery2) {
		int weight1 = battery1.getWeight();
		int weight2 = battery2.getWeight();
		int result = 0;
		// sort by descending weight
		if(weight1>weight2)
			result = -1;
		if(weight1<weight2)
			result = 1;
		if(weight1 == weight2)
			result = 0;
		return result;
	}
}
